package factoryMode.factory.simpleFactory.pizza;

/**
 * @author： pang-yun
 * @date： 2021-10-21 14:47
 * 功能目的 ：用于 披萨的简单工厂
 */
public class PizzaSimpleFactory {
    // 通过 orderType  来返回 对应的 pizza  实例
    public Pizza createPizza(String orderType) {
        Pizza pizza = null;
        System.out.println("simpleFactory + begin");
        if (orderType.equals("cheese")) {
            pizza = new CheesePizza();
            pizza.setName("cheese");
        } else if (orderType.equals("Greek")) {
            pizza = new GreekPizza();
            pizza.setName("Greek ");
        }

        if (pizza != null) {
            pizza.prepare();
            pizza.bake();
            pizza.cut();
            pizza.box();
        } else {
            System.out.println("订购披萨失败！！！");
        }
        return pizza;
    }


    // 通过静态方法创造 对象
    public static Pizza staticCreate(String orderType){
        Pizza pizza = null;
        System.out.println("simpleFactory + begin");
        if (orderType.equals("cheese")) {
            pizza = new CheesePizza();
            pizza.setName("cheese");
        } else if (orderType.equals("Greek")) {
            pizza = new GreekPizza();
            pizza.setName("Greek ");
        }

        if (pizza != null) {
            pizza.prepare();
            pizza.bake();
            pizza.cut();
            pizza.box();
        } else {
            System.out.println("订购披萨失败！！！");
        }
        return pizza;
    }


}
